import time
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.webdriver import WebDriver
from app_study.app_snowball_po.base.black_handle import black_wrapper


##基本的方法：driver, find, click, swipe
class BasePage:
    # black_list = [(MobileBy.ID, "com.xueqiu.android:id/tv_agree")]
    black_list = [(MobileBy.ID, "com.xueqiu.android:id/iv_action_back")]
    # black_list = [(MobileBy.ID, "com.xueqiu.android:id/iv_close")]

    def __init__(self, driver:WebDriver=None):
        self.driver = driver

    @black_wrapper
    def find(self, by, locator):
        return self.driver.find_element(by, locator)

    def find_and_click(self, by, locator):
        self.find(by, locator).click()

    def fing_and_send(self, by, locator, text):
        self.find(by, locator).send_keys(text)

    def find_and_gettext(self, by, locator):
        return self.find(by, locator).text

    def screenshot(self, name):
        # 截图
        self.driver.save_screenshot(name)

    def get_time(self):
        t = time.localtime(time.time())
        cur_time = time.strftime("%Y-%m-%d_%H_%M_%S, t")
        print(f"当前时间为：{cur_time}")
        return cur_time
